package com.example.wei.mvp.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.example.wei.mvp.R;
import com.example.wei.mvp.util.DensityUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;



/**
 * Created by win7 on 2017/7/25.
 */

public class TwoButtonIconDialog extends Dialog {

    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.tv_quit)
    TextView tvQuit;
    @BindView(R.id.tv_sure)
    TextView tvSure;
    private Activity activity;
    private String content;
    private String leftButton;
    private String rightButton;
    private OnDialogButtonClickListener listener;

    public TwoButtonIconDialog(Activity activity, String content, String leftButton, String rightButton, OnDialogButtonClickListener listener) {
        super(activity, R.style.MyDialogStyleTop);
        this.activity = activity;
        this.content = content;
        this.leftButton = leftButton;
        this.rightButton = rightButton;
        this.listener=listener;
        initView();
    }

    private void initView() {
        View view= LayoutInflater.from(getContext()).inflate(R.layout.dialog_custom_two, null);
        ButterKnife.bind(this,view);
        view.setPadding(DensityUtil.dip2px(getContext(),30),0,DensityUtil.dip2px(getContext(),30),0);
        tvContent.setText(content);
        tvQuit.setText(leftButton);
        tvSure.setText(rightButton);
        show();
        setContentView(view);
        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }


    @OnClick({R.id.tv_quit, R.id.tv_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_quit:
                dismiss();
                if (listener!=null){
                    listener.onLeftButtonClick();
                }
                break;
            case R.id.tv_sure:
                dismiss();
                if (listener!=null){
                    listener.onRightButtonClick();
                }
                break;
        }
    }
    public interface OnDialogButtonClickListener{
        void onLeftButtonClick();
        void onRightButtonClick();
    }



}
